<?php

$servidor = "localhost";
$usuario = "root";
$password = "gpi123"; //gpi123
$bd = "ruta";

$conexion = new mysqli($servidor, $usuario, $password, $bd);

if ($conexion->connect_errno) {
    $json['mensaje'] = "Connect failed: " . $conexion->connect_error;
    exit();
}

$conexion->autocommit("false");
// id del recorrido a buscar
$id = $_POST['id'];
// tipo 1 vuelta y 0 ida
$tipo = $_POST['tipo'];
if ($res = $conexion->query("SELECT * FROM `rec_calles` WHERE `id_recorrido`= '" . $id . "' AND `tipo` = '" . $tipo . "' ORDER BY `orden` ASC")) {
    $conexion->commit();
    $conexion->close();
} else {
    $conexion->rollback();
    $json['mensaje'] = 'Error al grabar.';
    exit();
}
$arreglo['total'] = $res->num_rows;
$i = 0;
while ($obj = $res->fetch_object()) {
    $arreglo['calles'][] = htmlentities($obj->calle);
}

$arreglo['mensaje'] = 'Grabado con éxito.';
echo (json_encode($arreglo));
?>